//
//  TLCategoryViewController.m
//  WXReader
//
//  Created by huaya on 2025/3/22.
//  Copyright © 2025 Andrew. All rights reserved.
//

#import "TLCategoryViewController.h"
#import "HMSegmentedControl.h"
#import "TLShortMoreBtnView.h"

#import "TLMallListTableViewCell.h"
#import "TLCategoryNovelTableViewCell.h"

#import "TLCategorySubModel.h"
#import "TLMallChannelModel.h"

#import "TLShortStoryViewController.h"

@interface TLCategoryViewController ()<UITableViewDelegate ,UITableViewDataSource>

@property (nonatomic, strong) UIButton *backBtn;
@property (nonatomic, strong) UIView *navView;
@property (nonatomic, strong) NSMutableArray *segTitleMArr;
@property (nonatomic, strong) HMSegmentedControl *segControl;

//@property (nonatomic, strong) UIScrollView *tagScrollView;
//@property (nonatomic, strong) UIButton *tagMoreBtn;

@property (nonatomic, strong) UIButton *shortStoryBtn;
@property (nonatomic, strong) UIButton *novelBtn;

@property (nonatomic, strong) TLShortMoreBtnView *shortBtn;

@property (nonatomic, strong) NSMutableArray *tagBtnArr;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSNumber *pageNumb;
@property (nonatomic, strong) NSNumber *pageSize;

@property (nonatomic, strong) NSString *typeStr;//0 短篇  1 长篇
@property (nonatomic, strong) NSNumber *shortTypeNumb;//1-人气,2-Time,3-Collect

@property (nonatomic, strong) TLCategorySubModel *selectedSubModel;

@property (nonatomic, strong) NSMutableArray *dataArr;

@property (nonatomic, strong) UIView *maskView;
@property (nonatomic, strong) UIView *shortListView;

@property (nonatomic, strong) UIButton *characterBtn;
@property (nonatomic, strong) UIButton *timeBtn;
@property (nonatomic, strong) UIButton *collectBtn;

@end

@implementation TLCategoryViewController
- (UIButton *)characterBtn{
    if (!_characterBtn) {
        _characterBtn = [[UIButton alloc] init];
        [_characterBtn setTitle:@"Trending" forState:UIControlStateNormal];
        [_characterBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateSelected];
        [_characterBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        _characterBtn.tag = 100;
        [_characterBtn addTarget:self action:@selector(shortBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _characterBtn;
}
- (UIButton *)timeBtn{
    if (!_timeBtn) {
        _timeBtn = [[UIButton alloc] init];
        [_timeBtn setTitle:@"New" forState:UIControlStateNormal];
        [_timeBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateSelected];
        [_timeBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        _timeBtn.tag = 200;
        [_timeBtn addTarget:self action:@selector(shortBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _timeBtn;
}
- (UIButton *)collectBtn{
    if (!_collectBtn) {
        _collectBtn = [[UIButton alloc] init];
        [_collectBtn setTitle:@"Best sellers" forState:UIControlStateNormal];
        [_collectBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateSelected];
        [_collectBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        _collectBtn.tag = 300;
        [_collectBtn addTarget:self action:@selector(shortBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _collectBtn;
}
- (void)shortBtnAction:(UIButton *)sender{
    
    sender.selected = YES;
    
    if (sender.tag == 100) {
        self.timeBtn.selected = NO;
        self.collectBtn.selected = NO;
        self.shortTypeNumb = @(1);
        self.shortBtn.titleLab.text = @"Trending";
    }else if (sender.tag == 200){
        self.characterBtn.selected = NO;
        self.collectBtn.selected = NO;
        self.shortTypeNumb = @(2);
        self.shortBtn.titleLab.text = @"New";
    }else{
        self.characterBtn.selected = NO;
        self.timeBtn.selected = NO;
        self.shortTypeNumb = @(3);
        self.shortBtn.titleLab.text = @"Best sellers";
    }
    
    [self.tableView.mj_header beginRefreshing];
    
    [self showShortListView];
    
    [self.shortBtn setDefultStatusImgView];
}
- (void)showShortListView{
    
    if (self.maskView.hidden) {
        self.maskView.hidden = NO;
        self.shortListView.hidden = NO;
        [UIView animateWithDuration:0.3 animations:^{
            [_maskView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.3]];
            [_shortListView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.right.equalTo(self.tableView);
                make.top.mas_equalTo(self.tableView.mas_top).offset(0);
                make.height.offset(110);
            }];
            [self.view layoutIfNeeded];
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            [_maskView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0]];
            [_shortListView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.right.equalTo(self.tableView);
                make.top.mas_equalTo(self.tableView.mas_top).offset(-110);
                make.height.offset(110);
            }];
            [self.view layoutIfNeeded];
        }completion:^(BOOL finished) {
            self.maskView.hidden = YES;
            self.shortListView.hidden = YES;
        }];
    }
    
}
- (UIView *)shortListView{
    if (!_shortListView) {
        _shortListView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 110)];
        [_shortListView setBackgroundColor:[UIColor whiteColor]];
        UIBezierPath *corner = [UIBezierPath bezierPathWithRoundedRect:_shortListView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(16.0, 16.0)];
        CAShapeLayer *layer = [CAShapeLayer layer];
        layer.path = corner.CGPath;
        _shortListView.layer.mask = layer;
        _shortListView.hidden = NO;
        float height = 110/3;
        
        [_shortListView addSubview:self.characterBtn];
        [self.characterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(_shortListView);
            make.height.offset(height);
        }];
        [_shortListView addSubview:self.timeBtn];
        
        [self.timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_shortListView);
            make.top.equalTo(self.characterBtn.mas_bottom);
            make.height.offset(height);
        }];
        [_shortListView addSubview:self.collectBtn];
        
        [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_shortListView);
            make.top.equalTo(self.timeBtn.mas_bottom);
            make.height.offset(height);
        }];
        
        self.shortBtn.titleLab.text = @"Trending";
        self.characterBtn.selected = YES;
        
    }
    return _shortListView;
}
- (UIView *)maskView{
    if (!_maskView) {
        _maskView = [[UIView alloc] init];
        [_maskView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0]];
        MJWeakSelf
        UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            [weakSelf showShortListView];
        }];
        [_maskView setUserInteractionEnabled:YES];
        [_maskView addGestureRecognizer:tapG];
        
    }
    return _maskView;
}
- (NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray new];
    }
    return _dataArr;
}
- (NSMutableArray *)segTitleMArr{
    if (!_segTitleMArr) {
        _segTitleMArr = [NSMutableArray new];
    }
    return _segTitleMArr;
}
- (TLShortMoreBtnView *)shortBtn{
    if (!_shortBtn) {
        _shortBtn = [TLShortMoreBtnView createView];
        MJWeakSelf
        _shortBtn.didSelectedBlock = ^{
            [weakSelf shortMoreAction];
        };
    }
    return _shortBtn;
}
- (UIButton *)novelBtn{
    if (!_novelBtn) {
        _novelBtn = [[UIButton alloc] init];
        [_novelBtn setImage:[UIImage imageNamed:@"book-line"] forState:UIControlStateNormal];
        [_novelBtn setImage:[UIImage imageNamed:@"book-line-select"] forState:UIControlStateSelected];
        [_novelBtn setTitle:@"novel" forState:UIControlStateNormal];
        [_novelBtn addTarget:self action:@selector(swithBookAction:) forControlEvents:UIControlEventTouchUpInside];
        [_novelBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        [_novelBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateSelected];
        _novelBtn.titleLabel.font = MK_FONT_PFSC_Medium(14);
        _novelBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0);
    }
    return _novelBtn;
}
- (UIButton *)shortStoryBtn{
    if (!_shortStoryBtn) {
        _shortStoryBtn = [[UIButton alloc] init];
        [_shortStoryBtn setImage:[UIImage imageNamed:@"file-paper-2-line"] forState:UIControlStateNormal];
        [_shortStoryBtn setImage:[UIImage imageNamed:@"file-paper-2-line-select"] forState:UIControlStateSelected];
        [_shortStoryBtn setTitle:@"short story" forState:UIControlStateNormal];
        [_shortStoryBtn addTarget:self action:@selector(swithBookAction:) forControlEvents:UIControlEventTouchUpInside];
        [_shortStoryBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        [_shortStoryBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateSelected];
        _shortStoryBtn.titleLabel.font = MK_FONT_PFSC_Medium(14);
        _shortStoryBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0);
    }
    return _shortStoryBtn;
}
- (void)swithBookAction:(UIButton *)button{
    button.selected = YES;
    if (button == _shortStoryBtn) {
        self.typeStr = @"0";
    }else{
        _shortStoryBtn.selected = NO;
    }
    
    if (button == _novelBtn){
        self.typeStr = @"1";
    }else{
        _novelBtn.selected = NO;
    }
    [self.tableView.mj_header beginRefreshing];
    
}
- (UIView *)navView{
    if (!_navView) {
        _navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, PUB_NAVBAR_HEIGHT)];
        [_navView setBackgroundColor:[UIColor whiteColor]];
        _backBtn = [[UIButton alloc] initWithFrame:CGRectMake(6, PUB_NAVBAR_HEIGHT - 28 - 6, 28, 28)];
        [_backBtn setImage:[UIImage imageNamed:@"tzxqy_fh"] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
        
        [_navView addSubview:_backBtn];
        
    }
    return _navView;
}
- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.pageNumb = @(1);
    self.pageSize = @(10);
    self.shortTypeNumb = @(1);
    self.typeStr = @"0";
    
    [self setUI];
    [self networkForCategory];
}
- (void)setUI{
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.navView];
    [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(self.view);
        make.width.mas_offset(kScreenWidth);
        make.height.mas_offset(PUB_NAVBAR_HEIGHT);
    }];
    [self.navView addSubview:self.segControl];
    [self.segControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.navView.mas_left).offset(35);
        make.right.equalTo(self.navView.mas_right).offset(15);
        make.height.mas_offset(40);
        make.bottom.equalTo(self.navView.mas_bottom);
    }];
//    [self.view addSubview:self.tagScrollView];
//    [self.tagScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left);
//        make.top.equalTo(self.navView.mas_bottom);
//        make.right.equalTo(self.view.mas_right).offset(-40);
//        make.height.offset(30);
//    }];
//    [self.view addSubview:self.tagMoreBtn];
//    [self.tagMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.view.mas_right);
//        make.left.equalTo(self.tagScrollView.mas_right);
//        make.top.equalTo(self.navView.mas_bottom);
//        make.height.offset(30);
//    }];
    [self.view addSubview:self.shortStoryBtn];
    self.shortStoryBtn.selected = YES;
    [self.shortStoryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(16);
        make.top.equalTo(self.navView.mas_bottom).offset(5);
        make.height.offset(30);
        make.width.offset(110);
    }];
    [self.view addSubview:self.novelBtn];
    self.novelBtn.hidden = YES;
    [self.novelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shortStoryBtn.mas_right).offset(10);
        make.top.equalTo(self.navView.mas_bottom).offset(5);
        make.height.offset(30);
        make.width.offset(60);
    }];
    [self.view addSubview:self.shortBtn];
    [self.shortBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-16);
        make.centerY.equalTo(self.novelBtn.mas_centerY);
        make.height.offset(30);
        make.width.offset(100);
    }];
    [self.view insertSubview:self.tableView atIndex:0];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view);
        make.top.equalTo(self.shortBtn.mas_bottom);
    }];
    
    UIView *bgView = [[UIView alloc] init];
    [bgView setBackgroundColor:[UIColor whiteColor]];
    [self.view insertSubview:bgView atIndex:1];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        make.bottom.equalTo(self.tableView.mas_top);
    }];
    
    [self.view insertSubview:self.maskView atIndex:1];
    [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.tableView);
    }];
    self.maskView.hidden = YES;
    
    [self.view insertSubview:self.shortListView atIndex:2];
    [self.shortListView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.tableView);
        make.top.mas_equalTo(self.tableView.mas_top).offset(-110);
        make.height.offset(110);
    }];
    
}
//- (void)createTagBtnsAction{
//    
//    self.tagBtnArr = [@[@"12",@"23",@"34",@"45",@"5623"] mutableCopy];
//    
//    [self.tagScrollView removeAllSubviews];
//    
//    CGFloat currentX = 16;
//    for (NSInteger i = 0; i < self.tagBtnArr.count; i++) {
//        NSString *title = self.tagBtnArr[i];
//        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//        
//        // 配置按钮属性
//        [button setTitle:title forState:UIControlStateNormal];
//        button.titleLabel.font = [UIFont systemFontOfSize:12];
//        [button setTitleColor:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]
//                    forState:UIControlStateNormal];
//        button.tag = 100 + i;
//        
//        // 计算文本宽度
//        CGSize textSize = [title sizeWithAttributes:@{NSFontAttributeName: button.titleLabel.font}];
//        CGFloat buttonWidth = textSize.width + 20; // 增加左右边距
//        
//        // 设置按钮frame
//        button.frame = CGRectMake(currentX, 5, buttonWidth, 30);
//        
//        [button setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#F7F7F7"]]
//                          forState:UIControlStateNormal];
//        
//        [button setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#F19E70"]]
//                          forState:UIControlStateSelected];
//        
//        // 添加点击事件
//        [button addTarget:self
//                   action:@selector(buttonClicked:)
//         forControlEvents:UIControlEventTouchUpInside];
//        
//        button.layer.masksToBounds = YES;
//        button.layer.cornerRadius = 8;
//        
//        [self.tagScrollView addSubview:button];
//        
//        // 更新下一个按钮的X坐标
//        currentX += buttonWidth + 5;
//    }
//
//    // 设置滚动内容大小（减去最后一个间隔）
//    self.tagScrollView.contentSize = CGSizeMake(currentX - 5, 40);
//    
//}
- (void)tagMoreAction{
    
}
- (void)shortMoreAction{
    [self showShortListView];
}
- (void)buttonClicked:(UIButton *)btn{
    btn.selected = !btn.selected;
    
}
- (HMSegmentedControl *)segControl{
    if (!_segControl) {
        _segControl = [[HMSegmentedControl alloc] initWithSectionTitles:@[]];
        _segControl.backgroundColor = UIColor.clearColor;
        _segControl.titleTextAttributes = @{NSFontAttributeName : SYSTEM_FONT(12),
                                            NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#999999"]};
        _segControl.selectedTitleTextAttributes = @{NSFontAttributeName : BOLD_SYSTEM_FONT(14),
                                                    NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#333333"]};
        
        _segControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationNone;
        _segControl.segmentWidthStyle = HMSegmentedControlSegmentWidthStyleDynamic;
        MJWeakSelf
        _segControl.indexChangeBlock = ^(NSInteger index) {
            
            weakSelf.selectedSubModel = weakSelf.segTitleMArr[index];
            [weakSelf.tableView.mj_header beginRefreshing];
        };
    }
    return _segControl;
}

- (UITableView *)tableView{
    if (!_tableView) {
        UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, MK_SCREEN_SAVE_BOTTOM_HEIGHT)];
        footView.backgroundColor = UIColor.clearColor;
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor colorWithHexString:@"F8F8FA"];
        _tableView.tableFooterView = footView;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
        
        [_tableView registerNib:[UINib nibWithNibName:@"TLMallListTableViewCell" bundle:nil] forCellReuseIdentifier:@"TLMallListTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"TLCategoryNovelTableViewCell" bundle:nil] forCellReuseIdentifier:@"TLCategoryNovelTableViewCell"];
        
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadLastData)];
        header.lastUpdatedTimeLabel.hidden = YES;
        _tableView.mj_header = header;

        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        
    }
    return _tableView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([_typeStr isEqualToString:@"0"]) {
        return 155;
    }else{
        return 167;
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row<self.dataArr.count) {
        
        if ([_typeStr isEqualToString:@"0"]) {
            TLMallListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TLMallListTableViewCell"];
            
            TLMallChannelModel *model = self.dataArr[indexPath.row];
        
            cell.model = model;
            
            return cell;
        }else{
            
            TLCategoryNovelTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TLCategoryNovelTableViewCell"];
            
            TLMallChannelModel *model = self.dataArr[indexPath.row];
            
            cell.model = model;
            
            return cell;
        }
    }else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
            cell.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
        }
        return cell;
    }
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    TLMallChannelModel *model = self.dataArr[indexPath.row];
    
    if ([model.worksType isEqualToString:@"0"]) {
        //短篇
        TLShortStoryViewController *vc = [TLShortStoryViewController new];
        vc.worksId = model.worksId;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else{
        //长篇
//        TL_BookMallDetailViewController *vc = [TL_BookMallDetailViewController new];
//        vc.book_id = [model.worksId intValue];
//        [self.navigationController pushViewController:vc animated:YES];
    }
    
}

- (void)loadLastData{
    
    self.pageNumb = [NSNumber numberWithInt:1];
    [self.dataArr removeAllObjects];
    
    [self network];
}
- (void)loadMoreData{
    
    self.pageNumb = [NSNumber numberWithInt:(self.pageNumb.intValue+1)];
    
    [self network];
}
- (void)network{
    
    NSDictionary *param = @{
        @"categoryIds":[NSString stringWithFormat:@"%@",self.selectedSubModel.categoryDataId],
        @"worksType":self.typeStr,
        @"orderBy":self.shortTypeNumb,
        @"pageNum":self.pageNumb,
        @"pageSize":self.pageSize,
    };
    [APIManager sendGetRequest:[APIURLManager getCategoryQueryOsWorks] parameters:param model:nil success:^(BOOL success, id  _Nullable responseData, APIResponse * _Nonnull requestModel) {
        
        if (success) {
            
            NSArray *dataA = [TLMallChannelModel mj_objectArrayWithKeyValuesArray:requestModel.data[@"records"]];
            
            [self.dataArr addObjectsFromArray:dataA];
            
            [self.tableView reloadData];
            
            [self.tableView.mj_header endRefreshing];
            if (dataA.count<self.pageSize.intValue) {
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }else{
                [self.tableView.mj_footer endRefreshing];
            }
            
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
    }];
    
}
- (void)networkForCategory{
    
    [APIManager sendGetRequest:[APIURLManager getCategoryListSub] parameters:@{} model:nil success:^(BOOL success, id  _Nullable responseData, APIResponse * _Nonnull requestModel) {
        
        if (success) {
            
            NSLog(@"123");
            
            [self.segTitleMArr addObjectsFromArray:[TLCategorySubModel mj_objectArrayWithKeyValuesArray:requestModel.data]];
            
            self.selectedSubModel = self.segTitleMArr[0];
            
            NSMutableArray *titleStr = [NSMutableArray new];
            
            for (TLCategorySubModel *subModel in self.segTitleMArr) {
                
                [titleStr addObject:subModel.categoryDataName];
                
            }
            
            [self.segControl setSectionTitles:titleStr];
            
            [self network];
            
            
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        
    }];
    
}
@end
